﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace database_insert
{
    class Insertdata
    {//тут можно перегрузить функции для удобства
        MySql.Data.MySqlClient.MySqlConnection conn;
        MySql.Data.MySqlClient.MySqlCommand cmd;
        public Insertdata(MySql.Data.MySqlClient.MySqlConnection conn, MySql.Data.MySqlClient.MySqlCommand cmd)
        {
            this.conn = new MySql.Data.MySqlClient.MySqlConnection();
            this.conn = conn;
            //this.conn.Open();
            this.cmd = cmd;
        }
        public void insert_users(int user_id, string login, string password, int role, string mail)
        {
            cmd.CommandText = "INSERT INTO users(user_id,login,password,role,mail) VALUES(" + user_id + ",'" + login + "','" + password + "'," + role + ",'" + mail + "')";
            cmd.ExecuteNonQuery();
        }
        public void insert_users(double lat, double lng, int status, string registred, string name, string status_map, int id_instrument,int id_owner)
        {
            cmd.CommandText = "INSERT INTO instruments (lat,lng,status,registred,name_device,status_map,id_instrument,id_owner) " +
            "VALUES(" + lat + "," + lng + "," + status + ",'" + registred+ "','" + name + "','" + status_map + "'," + id_instrument + "," + id_owner + ")";
            cmd.ExecuteNonQuery();
        }
        public void insert_user_instruments(int user_id, int id_instrument)
        {
            cmd.CommandText = "INSERT INTO user_instruments(user_id,id_instrument) VALUES(" + user_id + "," + id_instrument + ")";
            cmd.ExecuteNonQuery();
        }
        public void insert_events(string name,string def,int severity,int id_instrument)
        {
            cmd.CommandText = "INSERT INTO events(name,def,severity,instruments_id_instrument) VALUES('"+name+"','"+def+"'," + severity + "," + id_instrument + ")";
            cmd.ExecuteNonQuery();
        }
    }
}
